package com.example.myproject.web;

import com.example.myproject.redis.pubsub.PublicTopic;
import com.example.myproject.redis.redission.service.RedisLockHelper;
import io.swagger.annotations.ApiOperation;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redis")
public class RedisPubSubController {
    private Logger logger = LoggerFactory.getLogger(RedisPubSubController.class);

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;


    private ChannelTopic topic = new ChannelTopic(PublicTopic.test_subscribe_topic);

    @ApiOperation(value="sendPubMsg", notes="sendMsg")
    @RequestMapping(value="/sendPubMsg", method= RequestMethod.GET)
    public void sendMsg(String msg) {
        redisTemplate.convertAndSend(topic.getTopic(), "收到消息了吗!:" + msg);
    }


}
